// @ts-ignore
/* eslint-disable */

/**
 * 该文件为 @umijs/openapi 插件自动生成，请勿随意修改。如需修改请通过配置 openapi.config.ts 进行定制化。
 * */

import { request, type RequestOptions } from '@/utils/request';
import axios from 'axios';
import { baseApiUrl } from '@/utils/request';
/** 账户登出 GET /api/account/logout */
export async function accountLogout(options?: RequestOptions) {
  return request<any>('/account/logout', {
    method: 'GET',
    ...(options || {}),
  });
}

/** 获取菜单列表 GET /api/account/menus */
export async function accountMenu(options?: RequestOptions) {
  return request<API.AccountMenus[]>('/account/menus', {
    method: 'GET',
    ...(options || {}),
  });
}

/** 更改账户密码 POST /api/account/password */
export async function accountPassword(body: API.PasswordUpdateDto, options?: RequestOptions) {
  return request<any>('user/change-password', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 获取权限列表 GET /api/account/permissions */
export async function accountPermissions(options?: RequestOptions) {
  return request<string[]>('/account/permissions', {
    method: 'GET',
    ...(options || {}),
  });
}

/** 获取账户资料 GET /api/account/profile */
export async function accountProfile(options?: RequestOptions) {
  return request<API.AccountInfo>('/account/profile', {
    method: 'GET',
    ...(options || {}),
  });
}

/** 更改账户资料 PUT /api/account/update */
export async function accountUpdate(body: API.AccountUpdateDto, options?: RequestOptions) {
  return request<any>('/account/update', {
    method: 'PUT',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 验证验证码 POST /api/account/verify-captcha */
export async function accountVerifyCaptcha(body: API.CaptchaInput, options?: RequestOptions) {
  return request<any>('/account/verify-captcha', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    isReturnResult: false, // 返回完整响应，包括code和msg
    ...(options || {}),
  });
}

/** 获取验证码图片 GET /api/account/captcha */
export async function accountCaptcha() {
  try {
    // 直接使用浏览器的fetch API获取图片二进制数据
    const response = await fetch(`${baseApiUrl}account/captcha`, {
      method: 'GET',
      cache: 'no-cache'
    });
    
    if (!response.ok) {
      throw new Error('获取验证码失败');
    }
    
    // 转换为Blob对象并创建URL
    const blob = await response.blob();
    return URL.createObjectURL(blob);
  } catch (error) {
    console.error('获取验证码失败:', error);
    throw error;
  }
}
